package domain;

import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.Vector;

public class Paper {
	private UUID paperID;

	private String title;
	private Vector<Author> authors;
	private int year;
	private String topic;
	private String documentUrl;
	private String dblpUrl;

	public Paper() {
		this.paperID = UUID.randomUUID();
		this.authors = new Vector<Author>();
	}

	public Paper(String title, Vector<Author> authors, int year, String topic,
			String pLink, String aAbs) {
		this();

		this.title = title;
		this.authors = authors;
		this.year = year;
		this.topic = topic;
		this.documentUrl = pLink;
	}

	public UUID getPaperID() {
		return this.paperID;
	}

	public String getTitle() {
		return this.title;
	}

	public void setTitle(String value) {
		this.title = value.trim();
	}

	public List<String> getAuthorNames() {
		Vector<String> names = new Vector<String>();
		
		for(Author author : this.authors)
			names.add(author.getFullName());

		return Collections.unmodifiableList(names);
	}
	
	public List<Author> getAuthors() {
		return Collections.unmodifiableList(this.authors);
	}

	public void addAuthor(Author value) {
		if (value != null && !this.authors.contains(value)) {
			this.authors.add(value);
			value.addPaper(this);
		}
	}

	public int getYear() {
		return this.year;
	}

	public void setYear(int value) {
		this.year = value;
	}

	public String getTopic() {
		return this.topic;
	}

	public void setTopic(String value) {
		this.topic = value.trim();
	}

	public String getDocumentUrl() {
		return this.documentUrl;
	}

	public void setDocumentUrl(String value) {
		this.documentUrl = value.trim();
	}
	
	public String getDblpUrl() {
		return this.dblpUrl;
	}
	
	public void setDblpUrl(String value) {
		this.dblpUrl = value;
	}


	@Override
	public String toString() {

		return String.format(
				"TITLE: %s [%d]\n" + 
				"AUTHORS: %s\n" +
				"DBLP URL: %s\n",
				this.title, 
				this.year, 
				this.getAuthorNames().toString().replace("[", "").replace("]", ""), 
				this.dblpUrl);
	}

	@Override
	public boolean equals(Object obj) {
		if (!Paper.class.isInstance(obj))
			return false;
		Paper other = (Paper) obj;
		return other.title.equalsIgnoreCase(this.title)
				&& other.year == this.year;
		// TODO: Add any missing comparison objects
	}

	public void setPaperLink(String link) {
		System.out.println("LINK: "+link);
	}
}
